#include "loop_module/loop.h"
#include "timer_task.h"

#include <cstdio>
#include <gtest/gtest.h>

TEST(TestTimerTask, Task)
{
    Loop      loop;
    TimerTask timer(&loop);

    timer.ExpireFromNow(10 * 1000, []() { printf("tiemr trigger.\n"); });
    loop.Run();
}

TEST(TestTimerTask, CancelTest)
{
    Loop      loop;
    TimerTask timer(&loop);
    timer.ExpireFromNow(10 * 1000, []() { printf("tiemr trigger.\n"); });
	TimerTask cancel_task(&loop);
	cancel_task.ExpireFromNow(5 * 1000, [&timer](){

		printf("new timer trigger.\n");
		timer.Cancel();
	});
    loop.Run();
}

TEST(Interval, Test)
{
    Loop      loop;
    TimerTask timer(&loop);
    timer.ExpireFromNow(5 * 1000, [&timer]() {

        printf("tiemr trigger1.\n");
        int result = timer.ExpireFromNow(5 * 1000, [&timer] {
        printf("tiemr trigger2.\n");
            // for stop
            timer.Cancel();
        });
        printf("reset result : %d.\n", result);
    });
    loop.Run();
}
